﻿namespace Skymate.Commands
{
    using Abp.Events.Bus;

    using Skymate.Lyjt.Core;

    /// <summary>
    /// 灯色状态,主动上报 命令
    /// </summary>
    public class LightColorStateReportedCommand : BaseLightCommand
    {
        public LightColorStateReportedCommand()
            : base(
                  ProtocolConst.OptionType.ActiveReporting,
                  ProtocolConst.ObjectType.RedState)
        {
        }

        public override void ExecuteCommand(LightAppSession session, SemaphoreRequestInfo requestInfo)
        {
            var message = $"灯色主动上报";
            this.ShowLog(session.RemoteEndPoint.ToString(),
                message,$"数据长度:{requestInfo.Body.Length}");
            if (requestInfo.Body.Length != 12)
            {
                return;
            }

            var state = LightColorState.Create(requestInfo.Body);
            EventBus.Default.Trigger(new LightColorStateReportedEvent(session.RemoteEndPoint.ToString(), state));
        }
    }
}